package org.cuppaper.aide;

import org.bukkit.ChatColor;
import org.cuppaper.command.AideCommand;
import org.cuppaper.listener.Listener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

public final class Aide extends JavaPlugin {

    @Override
    public void onEnable() {
        // 注册监听器
        Listener pluginListener = new Listener();
        var pluginManager = Bukkit.getPluginManager();
        pluginManager.registerEvents(pluginListener, this);
        
        // 注册命令
        var command = getCommand("aide");
        if (command != null) {
            command.setExecutor(new AideCommand(this));
            getLogger().info(ChatColor.GOLD + "[Aide]" + ChatColor.AQUA + "插件加载成功！");
        } else {
            getLogger().severe("命令 'Aide' 未正确配置！");
        }
    }

    @Override
    public void onDisable() {
        // 插件注销加载项
        getLogger().info(ChatColor.GOLD + "[Aide]" + ChatColor.GREEN + "插件已卸载！");
    }
    
    /**
     * 重新加载插件
     */
    public void reloadPlugin() {
        // 取消注册所有监听器
        Bukkit.getPluginManager().disablePlugin(this);
        Bukkit.getPluginManager().enablePlugin(this);
        getLogger().info(ChatColor.GOLD + "[Aide]" + ChatColor.AQUA + "插件已重新加载！");
    }
}
